export default function loadScript(options) {
    return new Promise((resolve, reject) => {
      if (document.getElementById(options.id)) {
        resolve();
        return;
      }
  
      const script = document.createElement('script');
      script.id = options.id;
      script.async = true;
      script.src = options.src;
      script.onload = resolve;
      script.onerror = reject;
  
      if (options.data) {
        Object.entries(options.data).forEach(([key, value]) => {
          script.setAttribute(`data-${key}`, JSON.stringify(value));
        });
      }
  
      document.head.appendChild(script);
    });
  }